{% extends 'king_admin_tmp/table_index.html' %}

{% block contenter %}
{% load tags %}
    <div class="row container-fluid jumbotron">

      <form class="form-horizontal" role="form" method="post" onsubmit="return SelectAllChosenData()">{% csrf_token %}
      <span style="color: red">{{ form_obj.errors }}</span>
      {% for field in form_obj %}
      <div class="form-group">
        <label  class="col-sm-2 control-label" style="font-weight: normal">
            {% if field.field.required %}
                <b>{{ field.label }}<span style="color: red">*</span></b>
            {% else %}
                {{ field.label }}
            {% endif %}
        </label>

        <div class="col-sm-6">
            {{ field }}
        </div>


      <div>
{#        <div class="col-sm-6">#}
{#            {% if field.name in admin_class.filter_horizontal %}#}
{#                <div class="col-md-5">#}
{#                    {% get_m2m_obj_list admin_class field as mTom_obj_list %}#}
{#                    <select name="" id="" multiple class="filter-select-box" >#}
{#                        {% for obj in mTom_obj_list %}#}
{#                            <option value="{{ obj.nid }}">{{ obj }}</option>#}
{#                        {% endfor %}#}
{#                    </select>#}
{#                </div>#}
{#            {% endif %}#}
{#        </div>#}
      </div>
      </div>
      {% endfor %}
      {% if not admin_class.readonly_table %}
      <div class="form-group">

{#          {% block obj_delete %}#}
{#          <div class="col-sm-2">#}
{#                <a class="btn btn-danger" href="{% url 'obj_delete' app_name table_name form_obj.instance.id %}">Delete</a>#}
{#          </div>#}
{#          {% endblock %}#}
          <div class="col-sm-10 container">
            <button type="submit" class="btn btn-danger pull-right"><a style="color: white" href="{% url 'table_obj_delete' app_name table_name form_obj.instance.nid %}">Delete</a></button>

            <button type="submit" class="btn btn-success pull-right">Save</button>

          </div>
      </div>
    {% endif %}
    </form>

<script>
    function MoveElementTo(ele,target_id,new_target_id) {
        var opt_ele = "<option value='" + $(ele).val() + "' ondblclick=MoveElementTo(this,'" + new_target_id +"','"+ target_id +"')>" + $(ele).text() + "</option>";
       // $(ele).off().dblclick($(ele), parent_id)
        $("#" +target_id).append(opt_ele);
        $(ele).remove();

    }


    function SelectAllChosenData() {

        $("select[tag='chosen_list'] option").each(function () {
            $(this).prop("selected",true);
        });

        //remove all disabled attrs
        $("form").find("[disabled]").removeAttr("disabled") ;

        return true;
    }
</script>


    </div>
{% endblock %}